package com.lzh.dlykserver.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzh.dlykserver.constant.Constants;
import com.lzh.dlykserver.entity.TDicType;
import com.lzh.dlykserver.mapper.TDicTypeMapper;
import com.lzh.dlykserver.query.DicTypeDTO;
import com.lzh.dlykserver.service.DicTypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DicTypeServiceImpl implements DicTypeService {

    @Resource
    private TDicTypeMapper tDicTypeMapper;

    @Override
    public List<TDicType> loadAllDicData() {
        return tDicTypeMapper.selectByAll();
    }

    @Override
    public PageInfo<TDicType> getDicTypes(Integer current, DicTypeDTO dicTypeDTO) {
        //设置PageHelper
        PageHelper.startPage(current, Constants.PAGE_SIZE);
        //查询
        List<TDicType> list = tDicTypeMapper.getDicTypes(dicTypeDTO);
        //封装分页数据到PageInfo
        PageInfo<TDicType> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public TDicType getDicTypeById(Integer id) {
        return tDicTypeMapper.selectByPrimaryKey(id);
    }

    @Override
    public int deleteDicTypeById(Integer id) {
        return tDicTypeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateDicType(TDicType dicType) {
        return tDicTypeMapper.updateByPrimaryKeySelective(dicType);
    }

    @Override
    public int addDicType(TDicType dicType) {
        return tDicTypeMapper.insertSelective(dicType);
    }

    @Override
    public int batchDeleteDicType(List<String> idList) {
        return tDicTypeMapper.batchDeleteDicType(idList);
    }
}
